package com.example.eventrun.slice;
import com.example.eventrun.ResourceTable;
import com.google.gson.Gson;
import com.zzrv5.mylibrary.ZZRCallBack;
import com.zzrv5.mylibrary.ZZRHttp;
import com.zzrv5.mylibrary.ZZRResponse;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ListContainer;
import ohos.agp.components.Text;
import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;
import okhttp3.*;
public class MainAbilitySlice extends AbilitySlice {
    ListContainer container;
    private OkHttpClient okHttpClient=new OkHttpClient();
    @Override
    public void onStart(Intent intent) {
        String url="https://way.jd.com/jisuapi/get?channel=头条&num=10&start=0&appkey=1eab6690b59eda53649e8ad98ca5ad03";
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        container= (ListContainer) findComponentById(ResourceTable.Id_listcontainer);
        ZZRHttp.get(url, new ZZRCallBack.CallBackString() {
            @Override
            public void onFailure(int i, String s) {

            }

            @Override
            public void onResponse(String s) {
                Gson gson=new Gson();
                date date=gson.fromJson(s ,date.class);
                item_listcontainer item_listcontainer=new
                        item_listcontainer(date.getResult().getResult().list,MainAbilitySlice.this);
                container.setItemProvider(item_listcontainer);
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
    public void RunUI(Runnable runnable){//主线程
        EventRunner eventRunner=EventRunner.getMainEventRunner();
        EventHandler eventHandler=new EventHandler(eventRunner);
        eventHandler.postSyncTask(runnable);
    }
    public void Runbg(Runnable runnable){
        //子线程
        EventRunner eventRunner=EventRunner.create();
        EventHandler eventHandler=new EventHandler(eventRunner);
        eventHandler.postTask(runnable,0,EventHandler.Priority.IMMEDIATE);
    }
}
